<template>
    <div class="acceptanceRegistration-increase">
        <!-- 新增弹窗 -->
        <a-modal
         :width=680
         :visible="visibleShow" 
         :title="addEditParameter.id?'编辑':'新增'" 
         @ok="handleOk" 
         :forceRender="true"
         :confirmLoading="confirmLoading"
         @cancel="visibleShow = false">
            <a-spin size="large" :spinning="spinning">
                <a-form v-if="visibleShow" :form="form" :label-col="{ span: 8 }" :wrapper-col="{ span: 12 }" @submit="handleSubmit">
                    <a-form-item label="任务名称">
                        <a-textarea
                         v-model="formState.rwName" 
                         placeholder="请输入任务名称"
                         v-decorator="['rwName', { initialValue:formState.rwName, rules: rules.rwName}]"
                         :autosize="{ minRows: 1, maxRows: 100 }" 
                         >
                        </a-textarea>
                    </a-form-item>
                    <a-form-item label="bean名称">
                        <a-input
                        v-model="formState.beanName" 
                        v-decorator="['beanName', { initialValue:formState.beanName, rules: rules.beanName}]"
                        placeholder="请输入bean名称" />
                    </a-form-item>
                    <a-form-item label="方法名称">
                        <a-input
                        v-model="formState.methodName" 
                        v-decorator="['methodName', { initialValue:formState.methodName, rules: rules.methodName}]"
                        placeholder="请输入方法名称" />
                    </a-form-item>
                    <a-form-item label="方法参数">
                        <a-input
                        v-model="formState.methodParams" 
                        placeholder="请输入方法参数" />
                    </a-form-item>
                    <a-form-item label="状态">
                        <compSelector
                            v-model="formState.jobStatus" 
                            compType="Radio"
                            :defaultValue="formState.jobStatus"
                            :options="[{label:'正常',value:'1'},{label:'暂停',value:'0'}]"
                        />
                    </a-form-item>
                    
                    <a-form-item label="每隔多少分钟执行">
                        <a-input-number id="inputNumber" v-model="formState.mgdsfzzx" :min="1" @change="forderChange" />
                    </a-form-item>
                    <a-form-item label="备注">
                        <vxe-textarea
                         v-model="formState.remark" 
                         placeholder="请输入备注"
                         :autosize="{ minRows: 4, maxRows: 100 }" 
                         >
                        </vxe-textarea>
                    </a-form-item>
                    <a-form-item label="cron表达式" v-if="formState.cronExpression">
                        {{ formState.cronExpression }}
                    </a-form-item>
                </a-form>
            </a-spin>
        </a-modal>
    </div>
</template>
<script>
import {typeInput, typeNumber, typeSelect, typeCheckbox, typeRadio} from '@/components/compSearchCriteria/ContractType'
import compSelector from '@/components/compSelector/compSelector'
import validator from '@/common/validator'
import {addServe, editServe} from './service/index'
export default {
    components:{
        compSelector
    },
    data(){
        return{
            addEditParameter:{},
            spinning:true,
            form: this.$form.createForm(this, { name: 'coordinated' }),
            visibleShow:false,
            confirmLoading:false,
            typeSelect:typeSelect,
            formState:{},
            rules:{
                rwName: [{
                    required: true,
                    message: '请输入任务名称',
                    trigger: 'blur',
                }],
                methodName: [{
                    required: true,
                    message: '请输入方法名称',
                    trigger: 'blur',
                }],
                beanName: [{
                    required: true,
                    message: '请输入bean名称',
                    trigger: 'blur',
                }],
            },
            formRequer:'',
            optionsArr:[],
            submittedSuccessfully:false,
        }
    },
    mounted(){
    },
    updated(){
        this.cancelLoading()
    },
    methods:{
        getData(val){
            this.addEditParameter = val
            this.formState = val
        },
        cancelLoading(){
            let timer = setInterval((val)=>{
                this.spinning = false
                clearInterval(timer);
            },500)
            
        },
        forderChange(val){
            //console.log(val)
            if(!val){
                this.formState.mgdsfzzx = 1
            }
        },
        handleSubmit(e) {
            // e.preventDefault();
            var formState = {}
            this.form.validateFields((err, values) => {
                if (!err) {
                    this.confirmLoading = true
                    formState = {
                        ...this.formState,
                        ...values
                    }
                    if(formState.id){
                        editServe(formState).then(res=>{
                            if(res.code == 200){
                                this.submittedSuccessfully = true
                                this.$message.success('修改成功')
                                this.confirmLoading = false
                                this.visibleShow = false
                                this.$emit('handleOk',true,this.formState.id)
                            }else{
                                this.$message.warning(res.message)
                                this.confirmLoading = false
                            }
                        })
                    }else{
                        addServe(formState).then(res=>{
                            if(res.code == 200){
                                this.$message.success('添加成功')
                                this.submittedSuccessfully = true
                                this.confirmLoading = false
                                this.visibleShow = false
                                this.$emit('handleOk',true,'')
                            }else{
                                this.$message.warning(res.message)
                                this.confirmLoading = false
                            }
                        })
                    }
                    
                }
            });
            
        },
        handleOk(){
            
            this.handleSubmit()
        }
    }

}

</script>
<style lang="less">
/* .ant-form-item-label{
    font-weight: 600;
} */
.acceptanceRegistration-increase{
    .ant-modal-title{
        font-weight: 600;
    }
    .ant-modal-header{
        background: #5ca3e5;
    }
    .ant-upload-list{
        display: none !important;
    }
    .ant-modal-footer .ant-btn-primary{
        border: 1px solid #5ca3e5 !important;
        background-color: #5ca3e5 !important;
        color: #fff !important;
    }
}
 
</style>